package xyz.jfshare.netty.study.client.bootstrap;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import xyz.jfshare.netty.study.client.handler.ChatClientInitializer;
import xyz.jfshare.netty.study.client.util.MenuUtil;

public class ChatClient {
    public static void main(String[] args) throws Exception{
        EventLoopGroup loopGroup = new NioEventLoopGroup();
        try {
            Bootstrap bootstrap = new Bootstrap();
            bootstrap.group(loopGroup).channel(NioSocketChannel.class)
                    .handler(new ChatClientInitializer());

            String port = "8899";
            if(args.length != 0){
                port = args[1];
            }

            Channel channel = bootstrap.connect("140.143.23.218", Integer.parseInt(port)).sync().channel();
            MenuUtil.MainMenu(channel);
        }finally {
            loopGroup.shutdownGracefully();
        }
    }
}
